home *** CD-ROM | disk | FTP | other *** search
/ MacHack 1997 / MacHack 1997.toast / Hacks / Hacks ’97 / Warrior’s Progress / source code / Source / Libraries / Trees / RedBlackLink.h < prev    next >
Encoding:
Text File  |  1997-06-28  |  3.3 KB  |  92 lines  |  [TEXT/CWIE]

  1. // RedBlackLink.h
  2.  
  3. #ifndef RedBlackLink_h
  4. #define RedBlackLink_h
  5.  
  6. #ifndef RedBlackKey_h
  7. #include "RedBlackKey.h"
  8. #endif
  9. #ifndef Link_h
  10. #include "Link.h"
  11. #endif
  12.  
  13. template < class Key, class Content > class RedBlackLinkTree;
  14. template < class Key, class Content > class RedBlackTreeLoop;
  15.  
  16. template < class KeyType, class ContentType >
  17. class RedBlackLink: private RedBlackKey<KeyType>,
  18.                           public Link<ContentType>
  19.   {
  20.     friend class RedBlackLinkTree< KeyType, ContentType >;
  21.     friend class RedBlackTreeLoop< KeyType, ContentType >;
  22.     
  23.     typedef RedBlackLink< KeyType, ContentType > Node;
  24.     typedef RedBlackLinkTree< KeyType, ContentType > TreeType;
  25.     typedef RedBlackKey<KeyType> NodeBase;
  26.     typedef RedBlackKeyTree<KeyType> TreeBase;
  27.     
  28.     private:
  29.         static Node *DownCast( NodeBase *n )                    { return static_cast< Node* >( n ); }
  30.         static const Node *DownCast( const NodeBase *n )    { return static_cast< const Node* >( n ); }
  31.  
  32.         static TreeType& DownCast( TreeBase& n );
  33.         static const TreeType& DownCast( const TreeBase& n );
  34.  
  35.     public:
  36.         RedBlackLink( const KeyType& theKey, ContentType *theContent = 0 )
  37.           : RedBlackKey<KeyType>( theKey ),
  38.              Link<ContentType>( theContent )
  39.           {}
  40.         
  41.         NodeBase::Key;
  42.         NodeBase::SetKey;
  43.                     
  44.         NodeBase::Owned;
  45.         TreeType& Owner()                        { return DownCast( NodeBase::Owner() ); }
  46.         const TreeType& Owner() const        { return DownCast( NodeBase::Owner() ); }
  47.  
  48.         Node *Parent()                            { return DownCast( NodeBase::Parent() ); }
  49.         const Node *Parent() const            { return DownCast( NodeBase::Parent() ); }
  50.  
  51.         Node *Left()                            { return DownCast( NodeBase::Left() ); }
  52.         const Node *Left() const            { return DownCast( NodeBase::Left() ); }
  53.  
  54.         Node *Right()                            { return DownCast( NodeBase::Right() ); }
  55.         const Node *Right() const            { return DownCast( NodeBase::Right() ); }
  56.         
  57.         Node *Next()                            { return DownCast( NodeBase::Next() ); }
  58.         const Node *Next() const            { return DownCast( NodeBase::Next() ); }
  59.  
  60.         Node *Previous()                        { return DownCast( NodeBase::Previous() ); }
  61.         const Node *Previous() const        { return DownCast( NodeBase::Previous() ); }
  62.  
  63.         Node *Sibling()                        { return DownCast( NodeBase::Sibling() ); }
  64.         const Node *Sibling() const        { return DownCast( NodeBase::Sibling() ); }
  65.         
  66.         bool operator==( const Node& n ) const        { return NodeBase::operator==(n); }
  67.         bool operator!=( const Node& n ) const        { return NodeBase::operator!=(n); }
  68.         bool operator>=( const Node& n ) const        { return NodeBase::operator>=(n); }
  69.         bool operator<=( const Node& n ) const        { return NodeBase::operator<=(n); }
  70.         bool operator>( const Node& n ) const        { return NodeBase::operator>(n); }
  71.         bool operator<( const Node& n ) const        { return NodeBase::operator<(n); }
  72.         
  73.         bool operator==( const KeyType& n ) const        { return NodeBase::operator==(n); }
  74.         bool operator!=( const KeyType& n ) const        { return NodeBase::operator!=(n); }
  75.         bool operator>=( const KeyType& n ) const        { return NodeBase::operator>=(n); }
  76.         bool operator<=( const KeyType& n ) const        { return NodeBase::operator<=(n); }
  77.         bool operator>( const KeyType& n ) const        { return NodeBase::operator>(n); }
  78.         bool operator<( const KeyType& n ) const        { return NodeBase::operator<(n); }
  79.  
  80.         NodeBase::IsRoot;
  81.         NodeBase::IsLeftChild;
  82.         NodeBase::IsRightChild;
  83.         
  84.         NodeBase::HasLeftChild;
  85.         NodeBase::HasRightChild;
  86.         NodeBase::IsLeaf;
  87.         
  88.         NodeBase::Depth;
  89.   };
  90.  
  91. #endif
  92.